""" This file will extract all the link form given source """
"""Example bug id =128552 """


import re, urllib2
   
def get_links(content):
    links = re.findall(r'(https?://\S+)', content, re.I)
    
    #print links
    return links



def get_complete_domain(link):
    complete_domain = link.split("//")[1].split("/")[0]
 #  
    complete_domain = clean_link(complete_domain)
    return complete_domain

def get_main_domain(link):
    complete_domain= (link.split("//")[1].split("/")[0])
    complete_domain = clean_link(complete_domain)
    temp = complete_domain.split(".")
    #print "temp = ", temp, len(temp)
    if len(temp) > 2:
        main_domain = temp[len(temp)-2]+"."+temp[len(temp)-1]
        
    else:
        main_domain = complete_domain
    print "main domain = ", main_domain
    return main_domain


def clean_link(link):
    link = link.split(")")[0]
    link  = link.split("\"")[0]
    link = link.split(">")[0]
    link = link.split(":")[0]
    link = link.split(",")[0]
    
    str_len = len(link)
    print ". link=", link, "str len=", str_len
    if str_len>0:
         if link[str_len-1] =='.':
            link = link[0:str_len-1]
            print "... link=", link
    
    return link



